import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import frontLayout from '@/frontLayout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: frontLayout,
    hidden: true,
    redirect: '/front/homePage',
    children: [{
      path: 'main',
      name: 'main',
      component: () => import('@/views/front/homePage/index'),
      meta: {title: '首页'}
    }]
  },

  {
    path: '/front',
    component: frontLayout,
    hidden: true,
    children: [
      {
        path: 'homePage',
        name: 'homePage',
        component: () => import('@/views/front/homePage/index'),
        meta: {title: '首页', icon: 'el-icon-user'}
      },
      {
        path: 'recruit',
        name: 'recruit',
        component: () => import('@/views/front/recruit/index'),
        meta: {title: '招聘', icon: 'el-icon-user'}
      },
      {
        path: 'lawyer',
        name: 'lawyer',
        component: () => import('@/views/front/lawyer/index'),
        meta: {title: '专业人员', icon: 'el-icon-user'}
      },
      {
        path: 'aboutMe',
        name: 'aboutMe',
        component: () => import('@/views/front/aboutMe/index'),
        meta: {title: '关于我们', icon: 'el-icon-user'}
      },
      {
        path: 'contactUs',
        name: 'contactUs',
        component: () => import('@/views/front/contactUs/index'),
        meta: {title: '联系我们', icon: 'el-icon-user'}
      },
      {
        path: 'link',
        name: 'link',
        component: () => import('@/views/front/link/index'),
        meta: {title: '友情链接', icon: 'el-icon-user'}
      },
      {
        path: 'orderCase',
        name: 'orderCase',
        component: () => import('@/views/front/orderCase/index'),
        meta: {title: '预约案件', icon: 'el-icon-user'}
      },
      {
        path: 'userHome',
        name: 'userHome',
        component: () => import('@/views/front/userHome'),
        meta: {title: '我的信息', icon: 'el-icon-user'}
      }
    ]
  },

  {
    path: '/admin',
    component: Layout,
    redirect: '/admin/dashboard',
    hidden: true
  },

  {
    path: '/admin/dashboard',
    component: Layout,
    children: [
      {
        path: 'index',
        meta: {title: '首页', icon: 'el-icon-s-home'},
        component: () => import('@/views/dashboard/index')
      },
    ]
  },

  {
    path: '/admin/Customer',
    component: Layout,
    meta: {title: '用户管理', icon: 'el-icon-user-solid'},
    children: [
      {
        path: 'index',
        meta: {title: '所有用户', icon: 'el-icon-s-grid'},
        component: () => import('@/views/Customer')
      },
      {
        path: 'add',
        meta: {
          title: '新增用户', icon: 'el-icon-circle-plus'
        },
        component: () => import('@/views/EditCustomer'),
        props: true
      }
    ]
  },

  {
    path: '/admin/Case',
    component: Layout,
    children: [
      {
        path: 'index',
        meta: {title: '案件管理', icon: 'el-icon-s-check'},
        component: () => import('@/views/Case')
      }
    ]
  },

  {
    path: '/admin/Lawyer',
    component: Layout,
    meta: {title: '律师管理', icon: 'el-icon-s-cooperation'},
    children: [
      {
        path: 'index',
        meta: {title: '所有律师', icon: 'el-icon-s-platform'},
        component: () => import('@/views/Lawyer')
      },
      {
        path: 'add',
        meta: {title: '添加律师', icon: 'el-icon-folder-add'},
        component: () => import('@/views/AddLawyer')
      }
    ]
  },

  {
    path: '/admin/Recruitment',
    component: Layout,
    meta: {title: '招聘管理', icon: 'el-icon-s-finance'},
    children: [
      {
        path: 'index',
        meta: {title: '招聘信息', icon: 'el-icon-s-opportunity'},
        component: () => import('@/views/Recruitment')
      },
      {
        path: 'add',
        meta: {title: '添加招聘信息', icon: 'el-icon-document-add'},
        component: () => import('@/views/AddRecruitment')
      }
    ]
  },

  // 404 page must be placed at the end !!!
  {path: '*', redirect: '/404', hidden: true}
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
